package com.chapter10;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.pojo.Book;

public class Test02_json {
    public static void main(String[] args) {

        // 把json格式的字符串，转为对象
        String jsonStr = "{\"author\":\"曹雪芹\",\"name\":\"红楼梦\",\"price\":39.9,\"sn\":\"SN0003\"}";

        JSONObject jsonObject = JSON.parseObject(jsonStr);

        String author = jsonObject.getString("author");
        String name = jsonObject.getString("name");
        Double price = jsonObject.getDouble("price");
        String sn = jsonObject.getString("sn");

        System.out.println(sn);
        System.out.println(name);
        System.out.println(price);
        System.out.println(author);


//        Book book = JSON.parseObject(jsonStr, Book.class);
//        System.out.println(book.getSn());
//        System.out.println(book.getName());
//        System.out.println(book.getPrice());
//        System.out.println(book.getAuthor());



    }
}
